//**************************************************************** 
//* Copyright (c) 2008 Ford Motor Company. All Rights Reserved. 
//* 
//* $$Workfile:   EconomicIndexValueFirstQuery.java  $$ 
//* $$Revision:   1.3  $$ 
//* $$Author:   TMALDON4  $$ 
//* $$Date:   Feb 06 2009 05:32:04  $$ 
//* 
//***************************************************************** 
package ar.com.ford.it.fullEconomics.persistence.dao.query;

import oracle.toplink.expressions.Expression;
import oracle.toplink.expressions.ExpressionBuilder;
import oracle.toplink.queryframework.ReportQuery;
import ar.com.ford.it.fullEconomics.persistence.dto.Teese01Economic;
import ar.com.ford.it.fullEconomics.persistence.dto.Teese03Econvalue;
import com.ford.it.persistence.impl.toplink.CustomExpressionFactory;

public class EconomicIndexValueFirstQuery implements CustomExpressionFactory {

    public Expression createExpression(ExpressionBuilder builder, Object[] parameters) {
        Teese01Economic economic = (Teese01Economic) parameters[0];
        String type = (String) parameters[1];
        Expression exp = null;
        ExpressionBuilder builderReport = new ExpressionBuilder();
        ReportQuery report = new ReportQuery();
                
        report = new ReportQuery(Teese03Econvalue.class, builderReport);
        report.addMinimum("eese03EcvalueEffectivDateY", builderReport.get("eese03EcvalueEffectivDateY"));
        report.setSelectionCriteria(builderReport.get("teese01Economic").equal(economic));
        
        exp = builder.get("teese01Economic").equal(economic);
        exp = exp.and(builder.get("eese03EcvalueTypeCodeC").equalsIgnoreCase(type));                        
        exp = exp.and(builder.get("eese03EcvalueEffectivDateY").equal(exp.subQuery(report)));
        
        return exp;
    }

}
